package com.ie.service.before;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ie.common.http.ResponseResult;
import com.ie.common.security.utils.ConfigrarionBean;
import com.ie.common.security.utils.JwtTokenUtil;
import com.ie.common.security.utils.MD5Util;
import com.ie.common.security.utils.RedisUtil;
import com.ie.entity.BUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public abstract class BUserServiceImpl extends ServiceImpl<BUserMapper, BUserEntity> implements BUserService {
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;
    @Autowired
    private ConfigrarionBean config;

    // 已有代码...

    @Override
    public ResponseResult<Map<String, String>> changePassword(String email, String oldPassword, String newPassword) {
        BUserEntity user = lambdaQuery().eq(BUserEntity::getBemail, email).one();
        if (user == null) {
            return ResponseResult.getMessageResult(null, "A001"); // 用户不存在
        }
        if (!user.getBpwd().equals(MD5Util.MD5(oldPassword))) {
            return ResponseResult.getMessageResult(null, "A002"); // 旧密码错误
        }
        user.setBpwd(MD5Util.MD5(newPassword));
        if (updateById(user)) {
            return ResponseResult.getMessageResult(null, "A003"); // 密码修改成功
        }
        return ResponseResult.getMessageResult(null, "A004"); // 密码修改失败
    }
}